﻿var deptTree;
$(initPage);
function initPage() {
	$("ul","#leftTree").load("m/submit_flow/depttree", function(){
		 deptTree = $("#leftTree").simpleTree({
          animate: true,
          autoclose:false,
          selectRoot : false,
          docToFolderConvert : true,
          drag : false,
          afterClick : onClickNode
        })[0];
        deptTree.openNode($("li", "#rootDept").eq(1).attr("id"));
	});
	
}

function onClickNode(node) {
	var deptId = node.attr("id");
	$.post("m/submit_flow/deptuser", {
		deptId : deptId
	}, function(data) {
		if ($.checkErrorMsg(data) ) {
			var fileList = "";
			if(data.efUsers){
				var dataList = data.efUsers;
				$(dataList).each(function(i) {
					fileList += "<tr class='table_td_font' bgColor='#ffffff'>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap><a style='cursor:pointer;text-decoration:underline;color:#00f;' onclick=\"selectUser('" + dataList[i].userCode + "')\"'>选择</a></td>";
					fileList += "<td align='left'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].userCode + "</td>";
					fileList += "<td align='left'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].userName + "</td>";
					fileList += "</tr>";
				});
			}
			$("#data_list").html(fileList);
		} 
	}, "json");
}

function selectUser(userCode) {
	window.returnValue = userCode;
	window.close();
}